package com.mall.util;

import org.apache.shiro.crypto.hash.Sha384Hash;
import org.apache.shiro.crypto.hash.SimpleHash;
import static com.sun.javafx.font.FontResource.SALT;
import org.apache.shiro.crypto.hash.Md5Hash;

import java.util.UUID;

/**
 * @author little_super
 * @project hk_mall_background
 * @package com.mall.util
 * @create 2017-09-01 22:13
 */
public class SecurityUtil {

    public static String generateUUID(){
        String uuid = UUID.randomUUID().toString();
        return uuid;
    }

    public static String encrypt(String data) {
        String sha384Hex = new Sha384Hash(data).toBase64();
        return sha384Hex;
    }

    public static String getMD5(String str){
        Object obj = new SimpleHash("MD5", str, null, 1024);
        System.out.println(obj.toString());
        return obj.toString();
    }

    public static String getEncryotString1(String password,String SALT){
        //加密密码为32位散列,salt为ines,迭代次数为3次
        Md5Hash md5hash = new Md5Hash(password,SALT,1);
        //加密salt为32位散列
        Md5Hash salthash = new Md5Hash(SALT,password);
        //截取前八位8位
        String salthex = salthash.toHex().substring(0, 8);
        StringBuffer strBuffer = new StringBuffer();
        //拼装为40位md5的反转作为加密密文
        strBuffer.append(md5hash.toHex()).append(salthex).reverse();
        return strBuffer.toString();
    }

    public static String getEncryotString(String password,String SALT){
        SimpleHash sh = new SimpleHash("md5", password, SALT, 3);
        return sh.toString();
    }


    public static void main(String[] args) {
        System.out.println(getEncryotString("admin","admin"));
    }


}
